package charger;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;


public class Index_words {
	
	private final static Index_words instance = new Index_words();

	public static Index_words getInstance() {
		return instance;
	}
	
	private HashMap<Integer,String> liste_mot;

	private Index_words() {
		liste_mot = new HashMap<>();
	}
	
	public HashMap<Integer, String> getListe_mot() {
		return liste_mot;
	}

	public void chargeMots (String fichier) throws IOException
	{
		InputStream ips = new FileInputStream(fichier);
		InputStreamReader ipsr = new InputStreamReader(ips);
		BufferedReader br = new BufferedReader(ipsr);

		String ligne;
		int index;
		String mot;

		while ((ligne = br.readLine()) != null) {
			StringTokenizer chaine = new StringTokenizer(ligne, " ");
			mot = chaine.nextToken();
			index = Integer.parseInt(chaine.nextToken());
			liste_mot.put(index, mot);
		}

		br.close();
	}
}
